#ifndef __PLUG_COMMON_H__
#define __PLUG_COMMON_H__

#include "hi_type.h"
#include "mpp_help.h"
#include "hi_comm_ai_adapt.h"

#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif /* End of #ifdef __cplusplus */

#define PLUG_COMMON_DETECT_INTERVAL_MS  5000

#define PLUG_COMMON_LCD_WIDTH       800
#define PLUG_COMMON_LCD_HEIGHT      480

#define PLUG_COMMON_DATAMNG_DEV_INFO_FILE_PATH         "/hiopenais/deviceinfo.json"

#define PLUG_COMMON_PHOTO_FOLDER      "/hiopenais/photo"
#define PLUG_COMMON_VIDEO_FOLDER      "/hiopenais/video"

typedef enum tagPLUG_COMMON_GUIDER_TYPE_E
{       
    PLUG_COMMON_PERSON_PASSABLE_STRAIGHT = 1,       //行人道绿灯
    PLUG_COMMON_PERSON_IMPASSABLE_STRAIGHT,         //行人道红灯
    PLUG_COMMON_PERSON_SIDEWAYS,                    //行人道侧视
    PLUG_COMMON_NOPERSON_PASSABLE_STRAIGHT,         //非行人道绿灯
    PLUG_COMMON_NOPERSON_IMPASSABLE_STRAIGHT,       //非行人道绿灯
    PLUG_COMMON_NOPERSON_SIDEWAYS,                  //非行人道绿灯
    PLUG_COMMON_ZEBRA_CROSSING,                     //斑马线
    PLUG_COMMON_BUS_STOP,                           //公交站
    
    PLUG_COMMON_BUff
    
}PLUG_COMMON_GUIDER_TYPE_E;

typedef enum tagPLUG_COMMON_PUB_TYPE_E
{
    PLUG_COMMON_DEVICE_REGISTER = 0,
    PLUG_COMMON_DEVICE_RT_VIDEO,
    
    /* door type */
    PLUG_COMMON_DEVICE_TEMPERATURE,
    PLUG_COMMON_DEVICE_HUMIDITY,
    PLUG_COMMON_DEVICE_SMOKE,
    
    /* blind guide type */
    PLUG_COMMON_DEVICE_DISTANCE_AHEAD,  //前方距离
    PLUG_COMMON_DEVICE_DISTANCE_BELOW,  //下方距离
    PLUG_COMMON_DEVICE_GPS_LONGGITUDE,  //经度
    PLUG_COMMON_DEVICE_GPS_LATITUDE,    //纬度

    PLUG_COMMON_DEVICE_HEARTBEAT,   //心跳

    PLUG_COMMON_DEVICE_PHOTO,       //机柜门照片信息

    PLUG_COMMON_DEVICE_DETECT,       //导盲仪识别信息
    
    PLUG_COMMON_DEVICE_BUTT
}PLUG_COMMON_PUB_LIST_TYPE_E;


typedef enum tagPLUG_COMMON_DOOR_TYPE_E
{
	PLUG_COMMON_DOOR1_CLOSE = 1,
	PLUG_COMMON_DOOR1_OPEN,
	PLUG_COMMON_DOOR1_UNKNOW,

	PLUG_COMMON_DOOR2_CLOSE ,
	PLUG_COMMON_DOOR2_OPEN,
	PLUG_COMMON_DOOR2_UNKNOW,

	PLUG_COMMON_DOOR3_CLOSE ,
	PLUG_COMMON_DOOR3_OPEN,
	PLUG_COMMON_DOOR3_UNKNOW,

	PLUG_COMMON_DOOR_BUTT
}PLUG_COMMON_PUB_DOOR_TYPE_E;

typedef enum tagPLUG_COMMON_MOD_E
{
    PLUG_COMMON_MOD_LCD = 0, //lcd屏幕显示
    PLUG_COMMON_MOD_AI, //AI 插件PC tool aic venc
    PLUG_COMMON_MOD_RTSP, //RTSP流
    
    PLUG_COMMON_MOD_BUTT
}PLUG_COMMON_MOD_E;

typedef enum tagPLUG_COMMON_OSD_TYPE_E
{
    PLUG_COMMON_OSD_TIME = 0, //时间水印
    PLUG_COMMON_OSD_STRING,   //字符串水印
    
    PLUG_COMMON_OSD_BUTT
}PLUG_COMMON_OSD_TYPE_E;

typedef struct tagPLUG_COMMON_OSD_INFO
{
    PLUG_COMMON_OSD_TYPE_E enType;
    HI_CHAR azString[64];   //字符串，只针对PLUG_COMMON_OSD_STRING
    HI_U32 u32XCoordinate;  //X坐标
    HI_U32 u32YCoordinate;  //Y坐标
    HI_U32 u32Color;        //颜色
    HI_S32 s32FontWidth;    //字体宽度
    HI_S32 s32FontHeight;   //字体长度
}PLUG_COMMON_OSD_INFO;

/** Device Information */
typedef struct tagPLUG_COMMON_DEV_INFO_S
{
    HI_CHAR azDeviceId[64];     /* 设备ID */
    HI_CHAR azMqttAddress[64];  /* mqtt 服务器地址 */

    HI_CHAR azUserId[64];           /* 用户ID */
    HI_CHAR azPassword[64];         /* 用户密码 */
    HI_CHAR azStreamIp[64];         /* 推流地址 */
    HI_S32 s32StreamPort;       /* 推流端口 */

    HI_S32 s32TempThres;        /* 温度阈值 */
    HI_S32 s32HumThres;         /* 湿度阈值 */
    HI_S32 s32SmokeThres;       /* 烟感阈值 */

    HI_S32 s32DisAheadWarn;        /* 前距预警值 */
    HI_S32 s32DisBlowWarnHight;         /* 下距预警阈值（高） */
    HI_S32 s32DisBlowWarnLow;       /* 下距预警阈值（低） */
}PLUG_COMMON_DEV_INFO_S;

/* 实时温湿度 */
typedef struct tagPLUG_COMMON_DATA_INFO_S
{   
    /*door type*/
    double dTemperature;
    double dHumidity;
    double dSmoke;

    /* blind guide type */
    double dDistance_aHead;
    double dDistance_Below;
    double dGpsLongitude;       //经度
    double dGpslatitude;        //纬度
}PLUG_COMMON_DATA_INFO_S;

typedef struct tagPLUG_COMMON_AI_DATA_INFO
{
    HI_U8 *pu8Buff;
    HI_S32 s32Bufflen;
    HI_U64 u64Pts;
}PLUG_COMMON_AI_DATA_INFO;

/**
 * @brief    plug common get local IP.
 * @param[out] ip
 * @return 0 success,non-zero error code.
 * @exception    None
 */
HI_S32 PLUG_COMM_GetLoaclIP(HI_CHAR *pazIP);

/**
* @brief    plug common check is folder exist, if not create it
* @param[out] ip
* @return 0 success,non-zero error code.
* @exception    None
*/
HI_S32 PLUG_COMMON_CheckFolderExist(const HI_CHAR *pazFolder);


/**
 * @brief    plug common init.
 * @param[in] none
 * @return 0 success,non-zero error code.
 * @exception    None
 */
HI_S32 PLUG_COMMON_Init(HI_VOID);

HI_S32 PLUG_COMMON_RecvMsg(HI_U8 *pu8Payload);

/**
 * @brief    plug common SendMsg.
 * @param[in] none
 * @return 0 success,non-zero error code.
 * @exception    None
 */
HI_S32 PLUG_COMMON_SendMsg(HI_S32 fd, HI_VOID *buf);


/**
 * @brief    plug common take photo.
 * @param[in] none
 * @return 0 success,non-zero error code.
 * @exception    None
 */
HI_S32 PLUG_COMMON_TakePhoto(HI_VOID);

/**
 * @brief     get osd hdl
 * @param[in] enMod OsdSet mod
 * @return 0 success,non-zero error code.
 * @exception    None
 */
HI_S32 PLUG_COMMON_OsdsClear(PLUG_COMMON_MOD_E enMod);

/**
 * @brief     set osd hdl
 * @param[in] pstOsdSet OsdSet
 * @return 0 success,non-zero error code.
 * @exception    None
 */
HI_S32 PLUG_COMMON_SetOsdSet(PLUG_COMMON_MOD_E enMod, OsdSet* pstOsdSet);

/**
 * @brief     set osd hdl
 * @param[in] enMod OsdSet mod
 * @param[in] pstOsdInfo OsdSet info
 * @return 0 success,non-zero error code.
 * @exception    None
 */
HI_S32 PLUG_COMMON_UpdateOsdInfo(PLUG_COMMON_MOD_E enMod, PLUG_COMMON_OSD_INFO* pstOsdInfo);

/**
 * @brief    get device id.
 * @param[out] pazID: Id < 64 len
 * @return 0 success,non-zero error code.
 * @exception    None
 */
HI_S32 PLUG_COMMON_GetDeviceInfo(PLUG_COMMON_DEV_INFO_S *pstInfo);

/**
 * @brief    set device id.
 * @param[out] pazID: Id < 64 len
 * @return 0 success,non-zero error code.
 * @exception    None
 */
HI_S32 PLUG_COMMON_SetDeviceInfo(PLUG_COMMON_DEV_INFO_S stInfo);

/**
 * @brief    mqtt publish msg.
 * @param[in] enPubType: pub type
 * @param[in] payload :Msg
 * @return 0 success,non-zero error code.
 * @exception    None
 */
HI_S32 PLUG_COMMON_MQTT_PubClient(PLUG_COMMON_PUB_LIST_TYPE_E enPubType, HI_S8 *payload);

/**
 * @brief    take photo
 * @param[in] none
 * @return 1 true,0 false.
 * @exception    None
 */
HI_VOID PLUG_COMM_TakePhoto();

/**
 * @brief    recordmng start record
 * @param[in] none
 * @return 1 true,0 false.
 * @exception    None
 */
HI_VOID PLUG_COMM_StartRecord();

/**
 * @brief    recordmng stop record
 * @param[in] none
 * @return 1 true,0 false.
 * @exception    None
 */
HI_VOID PLUG_COMM_StopRecord();

/**
 * @brief    recordmng get record state
 * @param[in] none
 * @return 1 true,0 false.
 * @exception    None
 */
HI_BOOL PLUG_COMMON_GetRecodeState();


/**
 * @brief    plug common deinit.
 * @param[in] pazRootDir:Msgmng root path
 * @param[in] pazPrefix :Msg prefix
 * @return 0 success,non-zero error code.
 * @exception    None
 */
HI_S32 PLUG_COMMON_DeInit(HI_VOID);

#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* End of #ifdef __cplusplus */

#endif

